<template>
    <div>
        <h1>编辑</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>员工编号</td>
                    <td>{{ info.Codr }}</td>
                </tr>
                <tr>
                    <td>姓名</td>
                    <td><input type="text" v-model="info.Name"></td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td><input type="password" v-model="info.Pwd"></td>
                </tr>
                <tr>
                    <td>出生日期</td>
                    <td><input type="date" v-model="info.DateTime"></td>
                </tr>
                <tr>
                    <td>年龄</td>
                    <td><input type="text" v-model="info.Age"></td>
                </tr>
                <tr>
                    <td>头像</td>
                    <td><input type="file" @change="Imgs">
                        <img :src="info.Img" width="100" height="100" v-if="info.Img != ''">
                    </td>
                </tr>
                <tr>
                    <td>是否入职成功</td>
                    <td><input type="radio" name="s" v-model="info.IsAdmin" :value="true">成功
                        <input type="radio" name="s" v-model="info.IsAdmin" :value="false">未成功
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="str" v-model="info.ZTid" :value="1">出勤
                        <input type="radio" name="str" v-model="info.ZTid" :value="2">请假
                        <input type="radio" name="str" v-model="info.ZTid" :value="3">休假
                        <input type="radio" name="str" v-model="info.ZTid" :value="4">离职
                    </td>
                </tr>
                <tr>
                    <td>性别</td>
                    <td><input type="radio" name="st" v-model="info.Sex" :value="1">男
                        <input type="radio" name="st" v-model="info.Sex" :value="2">女
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="编辑" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
import moment from 'moment';
const router = useRouter();
const route = useRoute();
let info: any = reactive({
    "Id": route.query.id,
    "Name": "",
    "Pwd": "",
    "DateTime": "",
    "Age": '',
    "Img": "",
    "IsAdmin": '',
    "ZTid": '',
    "Sex": '',
    Codr: moment(new Date()).format('YYYYMMDD') +
        Math.random().toString().substring(2, 5)
})
const Imgs = (e: any) => {
    let obj = e.target.files[0];
    let f = new FormData();
    f.append('file', obj)
    axios({
        url: '/api/User/Img',
        method: 'post',
        data: f
    })
        .then(res => {
            console.log(res);
            info.Img = res.data
        })
        .catch(err => {
            console.log(err);

        })
}
onMounted(() => {
    getFind();
})
const ok = () => {
    axios({
        url: '/api/User/Update',
        method: 'put',
        data: info
    })
        .then(res => {
            console.log(res);
            if (res.data > 0) {
                alert('编辑成功')
                router.push('/')
                return;
            }
            else {
                alert('编辑失败')
                return;
            }
        })
}
const getFind = () => {
    axios({
        url: '/api/User/Find',
        method: 'get',
        params: { Id: route.query.id }
    })
        .then(res => {
            console.log(res);
            Object.assign(info, res.data)
            info.DateTime = res.data.DateTime.substring(0, 10)

        })
        .catch(err => {
            console.log(err);

        })
}
</script>

<style scoped></style>